package com.yycwxt.modules.admin.sale;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yycwxt.domain.Flowfee;
import com.yycwxt.domain.Flows;
import com.yycwxt.domain.Sale;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;
import java.util.Map;

@Mapper
public interface SaleMapper extends BaseMapper<Sale> {

//    @SelectProvider(type = SaleSelectProvider.class, method = "getsalesql")
//    List<Map<String, Object>> getsale(Integer zq);

    @Select("""
            select  id, account_date '账期',  shop_name '店铺'
                , sum(case when subject_code = '9001-01-002' then cost end) '实际销售金额'
                , count(order_number) '销售订单'
                , sum(case when subject_code = '1004-01-010' then cost end) 'SD佣金'
                , sum(case when subject_code = '1004-01-001' then cost end) '直通车'
                , sum(case when subject_code = '1004-01-002' then cost end) '超级推荐'
                , sum(case when subject_code = '1004-01-004' then cost end) '钻石展位'
                , sum(case when subject_code = '1004-01-003' then cost end) '淘宝客'
                , sum(case when subject_code = '1004-01-007' then cost end) '京东'
                , sum(case when subject_code = '1004-01-008' or subject_code = '1004-01-009' then cost end) '拼多多'
             from yycwxt_test.core_flows
             where (subject_code like '1004-%' or subject_code= '9001-01-002') and account_date = #{account_date}
             group by shop_name,id,account_date
            """)
    List<Map<String, Object>> getsale(int zq);

    @Select("""
            select  id, account_date '账期',  shop_name '店铺'
                , sum(case when subject_code = '9001-01-002' then cost end) '实际销售金额'
                , count(order_number) '销售订单'
                , sum(case when subject_code = '1004-01-010' then cost end) 'SD佣金'
                , sum(case when subject_code = '1004-01-001' then cost end) '直通车'
                , sum(case when subject_code = '1004-01-002' then cost end) '超级推荐'
                , sum(case when subject_code = '1004-01-004' then cost end) '钻石展位'
                , sum(case when subject_code = '1004-01-003' then cost end) '淘宝客'
                , sum(case when subject_code = '1004-01-007' then cost end) '京东'
                , sum(case when subject_code = '1004-01-008' or subject_code = '1004-01-009' then cost end) '拼多多'
             from yycwxt_test.core_flows
             where subject_code like '1004-%' or subject_code= '9001-01-002'
             group by shop_name,id,account_date
            """)
    List<Map<String, Object>> getall();




//    @Select("select * from core_flows")
//    List<Flows> getzq();


}
